<!--
 * @Descripttion: 
 * @version: 
 * @Author: -ViJia
 * @Date: 2022-03-22 11:36:42
 * @LastEditors: -ViJia
 * @LastEditTime: 2022-03-23 18:16:00
-->
<template>
    <div class="Main">
        <div style="padding:0 20px 20px;">
          <el-breadcrumb separator-class="el-icon-arrow-right" style="margin-top: 10px;">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>订单管理</el-breadcrumb-item>
            <el-breadcrumb-item :to="{ path: '/stewardShopOrder' }">商品订单</el-breadcrumb-item>
          </el-breadcrumb>
        </div>
        <div class="MainTitle">
            商品订单
        </div>
        <div class="MianContent">
            <div class="MainTopAction">
                <div class="flex align-center">
                    <span>下单时间：</span>
                    <el-date-picker
                      type="daterange"
                      v-model="valueTime"
                      @change="onDateChange"
                      range-separator="至"
                      start-placeholder="开始日期"
                      end-placeholder="结束日期">
                    </el-date-picker>
                    <span style="margin-left:10px;">选择团队：</span>
                    <el-select v-model="stewardId" @change="selectSteward" clearable filterable placeholder="请输入团队名称选择">
                      <el-option
                        v-for="item in stewardList"
                        :key="item.value"
                        :label="item.name"
                        :value="item.id">
                      </el-option>
                    </el-select>
                    <el-button style="margin-left:10px;" icon="download" size="medium" type="primary" @click="ExportBtn">导出</el-button>
                </div>
                <div class="flex align-center">
                    <el-input v-model="keyword" clearable @change="InputChange" style="width: 300px;" placeholder="请输入订单信息查询" />
                    <el-button style="margin-left:10px;" type="primary" size="medium" @click="SeachKeyword">搜索</el-button>
                </div>
            </div>
            <div style="display:flex;align-items:center;">
                <div @click="TabsChange(item,index)" :class="['TabsItem',current == index?'TabsIndex':'']" v-for="(item,index) in TabsList" :key="item.id">{{item.name}}</div>
            </div>
            <div class="TableView">
                <Table :columns="listfields" :data-source="listData" :bordered="false" size="middle" :pagination="false">
                    <div slot="action" slot-scope="row, index">
                        <div>
                            <el-button type="primary" size="small" @click="GoOrderDetail(index)">详情</el-button>
                        </div>
                    </div>
                    <div slot="move_way" slot-scope="row, index">
                        {{index.move_way=='1'?'快递':index.move_way=='2'?'自提':''}}
                    </div>
                </Table>
                <Pagination :total="total" v-model="pageno" :pageSize.sync="pagesize" @change="handlePageChange" @onShowSizeChange="onShowSizeChange"></Pagination>
            </div>
        </div>
    </div>
</template>

<script>
    import { OrderList } from '@/components/superSteward/Order/Columns/Order'
    import Pagination from '@/common/pagination.vue'
    import Table from 'ant-design-vue/lib/table';
    import 'ant-design-vue/lib/table/style/css'; // 或者 ant-design-vue/lib/button/style/css 加载 css 文件


    export default {
        name: 'list',
        components: {
            Pagination,
            Table
        },
        data() {
            return {
                total: 0, //定义初始有多少条数据
                pageno: 1, //默认第几页
                pagesize: 10, //一页显示多少条数据
                keyword: '',
                keywordTime: '', //时间
                valueTime:[], //选中的时间
                current: 0, //tabs当前选中
                // 切换tabs选择列表
                TabsList: [{
                    id: 0,
                    name: '全部'
                }, {
                    id: 1,
                    name: '待支付'
                }, {
                    id: 2,
                    name: '待发货'
                }, {
                    id: 3,
                    name: '待收货'
                }, {
                    id: 4,
                    name: '已完成'
                }, {
                    id: 5,
                    name: '已关闭'
                }, ],
                OrderStatus: '',
                listfields: OrderList, //表头列表
                listData: [], //表格数据
                stewardList:[], //管家团队列表
                stewardId:'', //选择的管家团队id
            };
        },
        computed: {
            // ...mapState({}),
        },
        created() {},
        mounted() {
            let that = this;
            that.GetStewardList()
            that.GetList()
        },
        methods: {

            // 获取团队列表
            GetStewardList(){
              const that = this;
              that.$http.post('/api/root/StewardOrder/getStewadList').then(res=>{
                if(res.code == 1){
                  that.stewardList = res.data
                }
              })
            },

            // 选择管家团队
            selectSteward(){
              const that = this;
              that.page = 1;
              that.pagesize = 10;
              that.GetList()
            },

            //选择时间
            onDateChange() {
                let that = this;
                let startTime = that.valueTime?that.$moment(that.valueTime[0]).format('yyyy-MM-DD'):'';
                let endTime = that.valueTime?that.$moment(that.valueTime[1]).format('yyyy-MM-DD'):'';
                that.keywordTime = that.valueTime?startTime + ',' + endTime:'';
                // console.log(that.keywordTime);
                that.page = 1;
                that.pagesize = 10;
                that.GetList()
            },
            TabsChange(item, index) {
                let that = this
                that.current = index
                that.OrderStatus = item.id == 0 ? '' : item.id
                setTimeout(() => {
                    that.page = 1;
                    that.pagesize = 10;
                    that.GetList()
                });
            },
            InputChange(e) {
                let that = this
                if (that.keyword == '') {
                    that.page = 1;
                    that.pagesize = 10;
                    that.GetList()
                }
            },
            SeachKeyword() {
                let that = this;
                that.page = 1;
                that.pagesize = 10;
                that.GetList()
            },
            GoOrderDetail(row) {
                this.$router.push({ name: 'stewardShopOrderInfo', query: { id: row.id, back: 'OrderList' } })
            },
            // 获取数据列表API
            async GetList() {
                let that = this
                let params = {
                    keyword: that.keyword,
                    order_status: that.OrderStatus,
                    create_time: that.keywordTime,
                    steward_id: that.stewardId,
                    page: that.pageno,
                    pagesize: that.pagesize,
                }
                const res = await that.$http.post('/api/root/StewardOrder/getProductOrderList',params)
                if (res.code == '1') {
                    // console.log(res.data);
                    const data = res.data
                    if (data.list.length > 0) {
                        data.list.forEach((item, index) => {
                            item.key = item.id
                            item.create_time = that.$moment(item.create_time * 1000).format('YYYY-MM-DD  HH:mm:ss'); //时间戳转换成时间
                        })
                    }
                    // console.log(data);
                    that.total = data.total
                    that.listData = data.list
                }
            },

            // 导出按钮
            ExportBtn(){
                const that = this;
                let params = {
                    keyword: that.keyword,
                    order_status: that.OrderStatus,
                    create_time: that.keywordTime,
                    steward_id: that.stewardId,
                }
                that.$http.exportPost('/api/root/StewardOrder/exportProductOrderList',params).then(res=>{
                  console.log(res);
                  //创建一个隐藏的a连接，
                  const a = document.createElement('a');
                  let blob = new Blob([res], { type: "text/csv" });
                  let objectUrl = URL.createObjectURL(blob);
                  a.setAttribute("href", objectUrl);
                  let fileName = '商品' + that.TabsList[that.current].name + '订单.csv'
                  a.setAttribute("download", fileName);
                  a.click();
                })
            },

            //分页器 
            handlePageChange(pageno, pagesize) { //点击第几页触发的函数
                let that = this;
                that.pageno = pageno;
                that.pagesize = pagesize;
                that.GetList(); //这个是向后台请求的数据函数
            },
            //切换每页显示多少条
            onShowSizeChange(current, size) { //改变每页显示条目数的函数
                let that = this;
                //pagesize 变化的回调
                that.pageno = current;
                that.pagesize = size;
                that.GetList(); //这个是向后台请求的数据函数
            },
        },
    };
</script>

<style scoped lang="less">
    .Main {
        border-radius: 10px;
        overflow: hidden;
        background: #fff;

        .MainTitle {
            font-size: 24px;
            color: #333;
            margin: 10px 20px;
            position: relative;
        }

        .MainTitle:before {
            content: '';
            width: 40px;
            height: 12px;
            background: linear-gradient(270deg, rgba(0, 158, 238, 0) 0%, rgba(221, 169, 85, 0.3) 100%);
            position: absolute;
            bottom: 2px;
            left: 0;
        }

        .MianContent {
            padding: 10px 20px 20px 20px;

            .MainTopAction {
                margin-bottom: 20px;
                display: flex;
                align-items: center;
                flex-wrap: wrap;
                justify-content: space-between;
            }

            .TabsItem {
                padding: 10px 0;
                width: 70px;
                position: relative;
                margin-right: 24px;
                text-align: center;
                cursor: pointer;
                margin-bottom: 20px;
                color: #000;
            }

            .TabsIndex {
                color: #DDA955;
            }

            .TabsIndex::before {
                content: '';
                position: absolute;
                bottom: 0;
                left: 50%;
                transform: translate(-50%, 0%);
                width: 50px;
                height: 2px;
                background-color: #DDA955;
            }
        }
    }
</style>